//
// Created by 66477 on 2022/9/24.
//

#ifndef DATA_STRUCTURE_OLIST3_2_H
#define DATA_STRUCTURE_OLIST3_2_H

#include "Node3_2.h"

class OList3_2 {
private:
    Node3_2 *pointer = nullptr;
public:

    /**
     * 头插插入节点
     * @param x 传入的节点
     * @return
     */
    OList3_2 *insert(Node3_2 *x) {
        Node3_2 *p = x;
        if (pointer == nullptr) {
            pointer = p;
            pointer->setNext(pointer);
        } else {
            p->setNext(pointer->getNext());
            pointer->setNext(p);
        }
        return this;
    }

    /**
     * 往后旋转一位
     * @return
     */
    OList3_2 *listGo() {
        pointer = pointer->getNext();
        return this;
    }

    /**
     * 删除指向pointer节点的节点
     * @return
     */
    OList3_2 *print() {
        if (pointer == nullptr) {
            return this;
        } else if (pointer->getNext() == pointer) {
            cout << pointer->getDate() << endl;
        } else {
            Node3_2 *p = pointer;
            cout << p->getDate() << " ";
            p = p->getNext();
            while (pointer != p) {
                cout << p->getDate() << " ";
                p = p->getNext();
            }
            cout << endl;
        }
        return this;
    }
};

#endif //DATA_STRUCTURE_OLIST3_2_H
